<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>同比环比</title>
    <link href="../../layui/css/layui.css" rel="stylesheet" type="text/css">
    <script src="../../layui/layui.js"></script>
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <script src="../../js/jquery-1.8.3.js"></script>
    <script src="../../js/util.js"></script>
    <script>
        function getdate(number) {
            var myDate = new Date();
            //当前年份
            var nowyear = myDate.getFullYear();
            //当前月份
            var nowmonth = myDate.getMonth()+1;
            if (number == 365) {
                var date = nowyear - 1 + "." + nowmonth;
            } else {
                var month = nowmonth - number;
                var year = month > 0 ? nowyear : nowyear - 1;
                month = month > 0 ? month : month + 12;
                var date = year + "." + month;
            }
            return date;
        }


        function select() {
            var way = document.getElementsByName("way");
            for (var i = 0; i < way.length; i++) {
                if (way[i].checked) {
                    var url = way[i].value + ".html";
                    location.href = url;
                }
            }
        }

        layui.use(['table', 'jquery', 'element','layer'], function () {
           var form = layui.form;
            var $ = layui.$;
            var laydate = layui.laydate;
            var layer = layui.layer;
            var table = layui.table;
            $("#download").on('click', function () {
               /*  location.href = '/smsSendCompare/export?flag=county'; */
             var url = "/smsSendCompare/export?flag=county" + "&cityId=" + $("#cityId").val() + "&countyId=" + $("#countyId").val();
		   location.href=url;
            });
/*             //身份识别
            $(document).ready(function () {
                $.ajax({
                    type: 'post',
                    async: false,
                    url: '/util/findUser',
                    success: function (json) {
                        if (json.duty == 2) {
                            $("#city").remove();
                        }
                    }, error: function () {
                        layer.msg('系统异常，请联系管理员处理!');
                    }
                });
            }); */
            tableData = {
                elem: "#table",//表格id
                id: "modelReload", //id
               url: '/smsSendCompare/find',
                method: 'post',
                cellMinWidth: 100,
                request: {
                    pageName: 'page',
                    limitName: 'limit'
                },
                response: {
                    statusName: 'code',
                    statusCode: 0,
                    msgName: 'msg',
                    countName: 'count',
                    dataName: 'data'
                },
                where: {flag: 'county'},
                page: true,
                count: "count",
                limit: 10,
                limits: [10, 20, 30, 40, 50],
                layout: ['prev', 'page', 'next'],
                prev: "上一页",
                next: "下一页",
                totalRow:true,
                cols: [[ //表头
                   
                    {field: 'cityName', title: '地市', totalRowText: '合计'}
                    , {field: 'countyName', title: '区县'}

                    , {field: 'nowNumber', title: getdate(0), totalRow: true}
                    , {field: 'lastMonthNumber', title: getdate(1), totalRow: true}
                    , {field: 'lastYearMonthNumber', title: getdate(365), totalRow: true}
                    , {field: 'compareYearLastMonthNumber', title: '同比增长率', totalRow: true}
                    , {field: 'compareLastMonthNumber', title: '环比增长率', totalRow: true}
                ]], done: function (res) {
                    // console.log(JSON.stringify(res));
                    layer.close(index);
                }
            };
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            table.render(tableData);
            
              
            $('#query').on('click', function () {
             var cityId = $("#cityId").val();
             var countyId = $("#countyId").val();

                var index = layer.load(1, {
                    shade: [0.1,'#fff'] //0.1透明度的白色背景
                });
                table.reload('modelReload', {
                    method: 'post',
                    page: {
                        curr: 1
                    },
                    where: {
                        cityId:cityId,               
                        countyId: countyId,

                    }
                });
                layer.close(index);      
        });
        
                     //监听区县
            form.on('select(cityId)', function (data) {
                var data2 = selectCountyId(data.value);
                appendCounty(data2);
    
            });
            //根据城市ID查询区县
            function selectCountyId(cityId) {
                var data;
                var url = '/util/findCountyByCityId?cityId=' + cityId;
                $.ajax({
                        type: 'post',
                        async: false,
                        url: url,
                        success: function (json) {
                            data = json.data;
                        }, error: function () {
                            layer.msg('系统异常，请联系管理员处理!');
                        }
                    }
                );
                return data;
            }
            //动态拼接区县
            function appendCounty(data){
                if (data.length != null) {
                    var options = '<option value="">请先选择地市</option>';
                    for (var i = 0; i < data.length; i++) {
                        options += '<option value="' + data[i].countyId + '">' + data[i].countyName + '</option>';
                    }
                    $('#countyId').html(options);
                } else {
                    $('#countyId').html('该地市下没有区县');
                }
                form.render();
            }
            
        
                      
     
          

        });
    </script>
</head>
<body>
<div class="layui-content-body">
    <div class="scroll-box">
        <div class="breadcrumb-box">
              <span class="layui-breadcrumb" lay-separator="|">
 <a href="javascript:returnIndex2()">首页&nbsp;</a>
  <a href="">&nbsp;报表管理&nbsp;</a>
  <a href="">&nbsp;同比环比&nbsp;</a>
</span>
        </div>
        <div class="content-box ">
            <div class="form-select-box">
                <div class="layui-form layui-form-pane">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">查询方式</label>
                            <div class="layui-inline">
                                   <a href="sendCompareByCity.html" id="city"> <input type="radio" title="按地市" name="way" value="sendCompareByCity" ></a>
                                   <a href="sendCompareByCounty.html"> <input type="radio" title="按区县" name="way" value="sendCompareByCounty" checked="" ></a>
                                <a href="sendCompareByMgr.html"> <input type="radio" title="按项目" name="way" value="sendCompareByMgr" ></a>
                            </div>
                           <div class="layui-form-item">
                             <div class="layui-inline">
                            <label class="layui-form-label">地市</label>
                            <div class="layui-input-block">
                                <select name="cityId" lay-filter="cityId" id="cityId">
                                    <option value="">全部</option>
                                    <option value="11">苏州</option>
                                    <option value="12">淮安</option>
                                    <option value="13">宿迁</option>
                                    <option value="14">南京</option>
                                    <option value="15">连云港</option>
                                    <option value="16">徐州</option>
                                    <option value="17">常州</option>
                                    <option value="18">镇江</option>
                                    <option value="19">无锡</option>
                                    <option value="20">南通</option>
                                    <option value="21">泰州</option>
                                    <option value="22">盐城</option>
                                    <option value="23">扬州</option>
                                    <option value="25">省级</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
								<label class="layui-form-label">区县</label>
								<div class="layui-input-block" style="width:150px">
									<select name="countyId" lay-filter="countyId" id="countyId">
										<option value="">全部</option>
									</select>
								</div>
							</div>							
                                      
                        <div class="layui-inline">
                            <button class="layui-btn layui-btn-normal" id="query">查&nbsp;询</button>
                            <button class="layui-btn layui-btn-normal" id="download">导&nbsp;出</button>
                        </div>
                  </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="table-box">
                <table class="layui-table" id="table">
                </table>
            </div>
        </div>
    </div>
</div>
</body>
</html>